#!/bin/bash
############################################################
#名字：	CentOS7_install_jdk_tomcat8.sh
#功能：	CentOS7安装JDK1.8.0_211和Tomcat8
#作者：	star
#邮件：	star@funet8.com
#时间：      2020/09/14
#Version 1.0
#20200914  第一版
# 
#使用说明：
# wget https://gitee.com/funet8/centos7_java/raw/master/shell/CentOS7_install_jdk_tomcat8.sh
# sh CentOS7_install_jdk_tomcat8.sh
###########################################################

Software_PWD="/data/software/"
#Tomcat多端口####################
Tomcat_PORY='9080 9081'


###########################################################
#安装jdk
###########################################################
mkdir $Software_PWD
cd $Software_PWD
wget http://js.funet8.com/centos_software/jdk-8u211-linux-x64.tar.gz
mkdir /usr/local/java/
tar -zxvf jdk-8u211-linux-x64.tar.gz -C /usr/local/java/

echo '
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
'>> /etc/profile
source /etc/profile

ln -s /usr/local/java/jdk1.8.0_211/bin/java /usr/bin/java

java -version

###########################################################
#安装tomcat8
###########################################################

cd /data/software/
wget http://js.funet8.com/centos_software/apache-tomcat-8.5.41.tar.gz

tar -zxvf /data/software/apache-tomcat-8.5.41.tar.gz -C /data/
mv  /data/apache-tomcat-8.5.41/ /data/tomcat8/

##修改tomcat8配置
cd /data/tomcat8/conf
mv server.xml server.xml_bak
wget https://gitee.com/funet8/centos7_java/raw/master/conf/server.xml

cd /data/tomcat8/conf
mv logging.properties logging.properties_bak
wget https://gitee.com/funet8/centos7_java/raw/master/conf/logging.properties

cd /data/tomcat8/bin
mv catalina.sh catalina.sh_bak
wget https://gitee.com/funet8/centos7_java/raw/master/conf/catalina.sh
chmod +x  /data/tomcat8/bin/catalina.sh


for  port in  $Tomcat_PORY
do	
	##多端口测试页面
	mkdir -p /data/wwwroot/web/webapps$port/ROOT
	echo "hello jsp $port">/data/wwwroot/web/webapps$port/ROOT/index.jsp
	## 开放防火墙端口
	iptables -A INPUT -p tcp --dport $port -j ACCEPT
done

service iptables save
systemctl restart iptables.service
#启动服务
/data/tomcat8/bin/startup.sh
#开机启动
echo '###start tomcat8' >>/etc/rc.local 
echo '/data/tomcat8/bin/startup.sh' >>/etc/rc.local

echo '
/data/tomcat8/bin/shutdown.sh 
/data/tomcat8/bin/startup.sh'>/root/restart_tomcat.sh

#SEVERE: Could not contact [localhost:[8005]]. Tomcat may not be running.问题解决
#https://blog.csdn.net/Ferdinand_Du/article/details/89396975
#1,找到你的jdk目录例如’'jdk1.8.0_172-amd64 /jre/lib/security/",在该文件夹下打开编辑java.security文件(vim java.security)
#2,将 “securerandom.source=file:/dev/random”
#修改为 "securerandom.source=file:/dev/./urandom"
#3,重启tomcat就可以了

# vi /usr/local/java/jdk1.8.0_211/jre/lib/security/java.security














